"""
将请求方式区分为get和post，通过run_main来判断使用哪个请求方式
路径和cookies可为空，在请求内部判断        session咋搞？？
"""
import requests

def post_main(url,data,cookies=None):
	if cookies !=None:	
		res = requests.post(url=url,data=data,cookies=cookies,verify=False)
	else:
		res = requests.post(url=url,data=data,verify=False)
	return res
def get_main(url,data=None,cookies=None):
	if cookies !=None:	
		res = requests.get(url=url,data=data,cookies=cookies,verify=False)
	else:
		res = requests.get(url=url,data=data,verify=False)
	return res

def run_main(method,url,data=None,cookies=None):
	if method == 'post':
		res = post_main(url,data,cookies)
	elif method == 'get':
		res = get_main(url,data,cookies)
	else:
		print('method error')
	return res

if __name__ == "__main__":
	req_url = 'http://49.233.108.117:3000/api/v1/topics'
	request_data = {
		"page": 1,
		"tab": "ask",
		"limit": 1,
		"mdrender": "True"
	}
	res = run_main('get',req_url,request_data)
	print(res.json())
